"""
Case Type   : gs_preupgradechk工具
Case Name   : gs_preupgradechk工具检测所有项
Create At   : 2025/11/17
Owner       : chen
Description :
    1.检测所有项
Expect      :
    1.成功
History     :
"""

import unittest
import os
import re
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Common import Common
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

LOG = Logger()
primary_sh = CommonSH('PrimaryDbUser')

class Tools_Gs_Preupgradechk_TestCase0018(unittest.TestCase):
    def setUp(self):
        LOG.info(f'----{os.path.basename(__file__)} start----')
        self.pri_node = Node('PrimaryDbUser')
        self.com = Common()
        self.constant = Constant()
        LOG.info("---SetUp：检查数据库状态是否正常---")
        status = primary_sh.get_db_cluster_status()
        LOG.info(status)
        self.assertTrue("Degraded" in status or "Normal" in status)

    def test_gs_preupgradechk_tools(self):
        text = '----step1: 检测所有项; expect: 成功----'
        LOG.info(text)
        LOG.info(text)
        cmd = f"gs_preupgradechk -i A"
        LOG.info(cmd)
        result = self.pri_node.sh(f"source {macro.DB_ENV_PATH};"
                                    f"{cmd}").result()
        LOG.info(result)
        self.assertIn('disk', result)
        self.assertIn('CPU', result)
        self.assertIn('Memory', result)
        self.assertIn('replay', result)
        self.assertIn('process', result)
        self.assertIn('network', result)

    def tearDown(self):
        LOG.info('--------清理环境--------')
        status = primary_sh.get_db_cluster_status("detail")
        LOG.info(status)
        self.assertTrue("Degraded" in status or "Normal" in status)
        LOG.info(f"------{os.path.basename(__file__)} end------")
